<template>
  <div id="cost-chart">
    <span v-show="isShowHint">暂无数据</span>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      deviceName: [],
      seriesConfigList: [],
      isShowHint: false
    };
  },

  methods: {
    getDeviceInData(data) {
      if (data.length == 0) {
        this.isShowHint = true;
        return;
      } else {
        this.isShowHint = false;
      }
      this.deviceName = [];
      this.seriesConfigList = [];
      data.forEach(item => {
        this.deviceName.push(item.name);
        this.seriesConfigList.push({
          name: item.name,
          type: 'bar',
          data: [item.value],
          coordinateSystem: 'polar',
          roundCap: true
        })
      })
      this.seriesConfigList.sort(function (a, b) {
        return a.data[0] - b.data[0];
      })
      this.getChartData();
    },

    getChartData() {
      var echarts = require("echarts");
      var div = document.getElementById("cost-chart");
      var chart = echarts.init(div);
      chart.setOption({
        color: ['#f356ae', '#b75ff5', '#7a79f3', '#2bcbdc', '#fa695f',
          '#28e5bc', '#33cce0', '#b1e739', '#e5b23a', '#ef8532'],
        tooltip: {
          show: true,
          axisPointer: {
            type: "shadow",
            shadowStyle: {
              color: 'rgba(150,150,150,0.1)'
            }
          },
          padding: [4, 10],
          backgroundColor: "rgba(255 ,255 ,255 ,1)",
          borderColor: "#eee",
          borderWidth: "1",
          textStyle: {
            color: "#666"
          },
          extraCssText: "box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);",
        },
        angleAxis: {
          max: function(value) {
            return value.max + 2;
          },
          splitLine: {
            show: false,
            lineStyle: {
              color: '#caccd4',
            }
          },
          axisTick: {
            show: false,
            lineStyle: {
              color: '#caccd4',
            }
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#caccd4',
            }
          },
        },
        radiusAxis: {
          type: 'category',
          axisLine: {
            show: false,
            lineStyle: {
              color: '#caccd4',
            }
          }
        },
        legend: {
          show: true,
          orient: 'vertical',
          left: '1%',
          top: '2%',
          itemWidth: 22,
          itemHeight: 14,
          itemGap: 10,
          textStyle: {
            fontSize: 13,
            color: '#5c5c5c'
          },
          data: this.deviceName
        },
        polar: {
          radius:['10%','80%'],
          center: ['70%', '50%']
        },
        series: this.seriesConfigList
      });
    }
  }
};
</script>

<style  scoped>
  #cost-chart {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    color: #aaaaaa;
  }
</style>
